import Axios  from 'axios';
import Qs     from 'qs';
import Config from '@/config/config.js';
import iView  from 'iview';

Axios.interceptors.request.use((config) => {
    iView.LoadingBar.start();
    return config;
});

Axios.interceptors.response.use((response) => {
    iView.LoadingBar.finish();
    return response.data;
});

export function post(url, data) {
    return Axios({
        method: 'post',
        url: Config.api + url,
        data: Qs.stringify(data),
        timeout: Config.timeout
    })
};

export function get(url, params) {
    return Axios({
        method: 'get',
        url: Config.api + url,
        params,
        timeout: Config.timeout
    })
}
